<?php
namespace app\index\controller;
use think\Db;
use think\Request;
use think\Url;
use think\Session;
use think\Controller;
use think\Loader;

/**
 * 
 */
class Clothes extends Base
{
	/*成衣订单列表*/
	public function index()
	{	
		/*判断权限*/
		$authmenu = new \think\Authmenu();
		$uid = Session::get('manage_id');
		$auth=$authmenu->check($uid,'clothes_list');
		if($auth !=true)
		{
			$this->error('权限不足');
		}
		if(Request::instance()->isPost())
		{
			$name = Request::instance()->post('name');/*搜索 根据名称或者是订单号查询*/
			 $aa = preg_match('/[\x{4e00}-\x{9fa5}]/u', $name);/*判断里面有没有汉字*/
                if($aa == 1){/*说明有汉字，那就是暗名称搜*/
                    //$where .=" and title like '%".$name."%'";
                    $code = DB::name('clothes_code')->field('code')->where("name like '%".$name."%'")->select();
                   $arr = "";
                    foreach ($code as $key => $value) {
                    	$arr .= $value['code'].',';
                    }
                    $arr = substr($arr, 0 ,-1);
                    $where['code'] = array('in',$arr);	
                }else{/*没有就是面料编号*/
                    $where['orderid'] = array('like',"%$name%");
                }
		}
		$where['is_del'] = 0;
		$list = DB::name('clothes_order')->where($where)->order('id desc')->paginate(15);
		$page = $list->render();
		$list = $list->all();
		foreach ($list as $k => $v) {
			$list[$k]['category'] = DB::name('clothes_category')->where('id ='.$v['category'])->value('value');
			$list[$k]['color']	   = DB::name('clothes_color')->where('id = ' .$v['color'])->value('value');
			$list[$k]['size']     = DB::name('clothes_size')->where('id = '.$v['size'])->value('value');	
			switch ($v['status']) {
				case 'caiwu':/*财务审核*/
				$list[$k]['cao'] = '<a href="/index/clothes/cai/id/'.$v['id'].'" title="审核"><i class="iconfont icon-daishenhe"></i></a>&emsp;<a href="/index/clothes/show/id/'.$v['id'].'" title="查看"><i class="iconfont icon-chakan"></i></a>&emsp;<a href="javascript:;" title="删除" onclick="delorder('.$v['id'].')"><i class="iconfont icon-shanchu"></i></a>';
				$list[$k]['status'] = '<a data-toggle="modal"  href="/index/clothes/cai/id/'.$v['id'].'" ><span class="badge badge">待财审</span></a>';
				break;
				case 'reject'://审核驳回
				$list[$k]['status'] = '<a data-toggle="modal"  href="/index/clothes/update/id/'.$v['id'].'" ><span class="badge badge-danger">已驳回</span></a>';
				$list[$k]['cao'] = '<a href="/index/clothes/update/id/'.$v['id'].'" title="修改"><i class="iconfont icon-chakan1"></i></a>&emsp;<a href="/index/clothes/show/id/'.$v['id'].'" title="查看"><i class="iconfont icon-chakan"></i></a>&emsp;<a href="javascript:;" title="删除" onclick="delorder('.$v['id'].')"><i class="iconfont icon-shanchu"></i></a>';					
				break;	
				case 'cheng'://等待上传压缩包
				$list[$k]['status'] = '<a data-toggle="modal"  href="#"  title="上传"><span class="badge badge-info">待上传</span></a>';
				$list[$k]['cao'] = '<a data-toggle="modal"  href="#modal-form" onclick="getInfo('.$v['id'].')" title="上传"><i class="iconfont icon-shangchuan"></i></a>&emsp;<a href="/index/clothes/show/id/'.$v['id'].'" title="查看"><i class="iconfont icon-chakan"></i></a>&emsp;<a href="javascript:;" title="删除" onclick="delorder('.$v['id'].')"><i class="iconfont icon-shanchu"></i></a>';
				break;
				case 'upload'://压缩包已上传，等待下载
				$list[$k]['status'] = '<a data-toggle="modal" href="JavaScript:;" onclick="xiazai('.$v['id'].')"><span class="badge badge-primary">待下载</span></a>';
				
				$list[$k]['cao'] = '<a href="JavaScript:;" onclick="xiazai('.$v['id'].')" title="下载"><i class="iconfont icon-xiazai"></i></a>&emsp;<a href="/index/clothes/show/id/'.$v['id'].'" title="查看"><i class="iconfont icon-chakan"></i></a>&emsp;<a href="javascript:;" title="删除" onclick="delorder('.$v['id'].')"><i class="iconfont icon-shanchu"></i></a>';
				
				break;	
				case 'download'://已下载，待生成条码
				$list[$k]['status'] = '<a data-toggle="modal"  href="JavaScript:;" ><span class="badge badge-success">待打码</span></a>';

				$list[$k]['cao'] = '<a href="/index/clothes/create/id/'.$v['id'].'" title="生成条码"><i class="iconfont icon-tiaoma"></i></a>&emsp;<a href="/index/clothes/show/id/'.$v['id'].'" title="查看"><i class="iconfont icon-chakan"></i></a>&emsp;<a href="javascript:;" title="删除" onclick="delorder('.$v['id'].')"><i class="iconfont icon-shanchu"></i></a>';

				break;
				case 'code'://已生成条形码  待发货
				$list[$k]['status'] = '<a data-toggle="modal"  href="#modal-form_yundan" onclick="getInfo('.$v['id'].')" title="发货"><span class="badge badge-warning">待发货</span></a>';
				
				$list[$k]['cao'] = '<a data-toggle="modal"  href="#modal-form_yundan" onclick="getInfo('.$v['id'].')" title="发货"><i class="iconfont icon-fahuo"></i></a>&emsp;<a href="/index/clothes/show/id/'.$v['id'].'" title="查看"><i class="iconfont icon-chakan"></i></a>&emsp;<a href="javascript:;" title="删除" onclick="delorder('.$v['id'].')"><i class="iconfont icon-shanchu"></i></a>';
				break;
				case 'success':
				$list[$k]['status'] = '<a data-toggle="modal"  href="JavaScript:;" ><span class="badge badge-success">已发货</span></a>';
				$list[$k]['cao'] = '<a href="/index/clothes/show/id/'.$v['id'].'" title="查看"><i class="iconfont icon-chakan"></i></a>&emsp;<a href="javascript:;" title="删除" onclick="delorder('.$v['id'].')"><i class="iconfont icon-shanchu"></i></a>';
				break;
			}
		}
		return $this->fetch('index',[
			'list'		=>	$list,
			'page'		=>	$page,
		]);
	}	
	/*发布成衣订单*/
	public function addOrder()
	{
		/*判断权限*/
		$authmenu = new \think\Authmenu();
		$uid = Session::get('manage_id');
		$auth=$authmenu->check($uid,'clothes_add');
		if($auth !=true)
		{
			$this->error('权限不足');
		}
		if(Request::instance()->isPost())
		{
			$data = Request::instance()->post();
			$data['entry_id'] = Session::get('manage_id');
			$data['addtime'] = time();
			$data['status'] = 'caiwu';
			$data['orderid'] = time().rand(10000,99999);
			$res = DB::name('clothes_order')->insert($data);
			if($res)
			{
				$this->success('订单发布成功',url('index/index/index',array('con'=>'clothes','act'=>'index')));
			}else{
				$this->error('订单创建失败');
			}
		}
		$category = $this->getCategoryList();
		$color 	  = $this->getColorList();
		$size 	  = $this->getSizeList();
		return $this->fetch('add_order',[
			'category'		=>		$category,
			'color'			=>		$color,
			'size'			=>		$size,
		]);
	}
	/*成衣订单的财审-- 审核通过*/
	public function cai($id)
	{
		/*判断权限*/
		$authmenu = new \think\Authmenu();
		$uid = Session::get('manage_id');
		$auth=$authmenu->check($uid,'clothes_caiwu');
		if($auth !=true)
		{
			$this->error('权限不足');
		}
		if(Request::instance()->isPost())
		{
			$id = Request::instance()->post('id');
			$data['caiwu_id'] = Session::get('manage_id');
			$data['caiwu_time'] = time();
			$data['status'] = 'cheng';
			$res = DB::name('clothes_order')->where('id = '.$id)->setField($data);
			if($res)
			{
				$this->success('审核成功',url('index/index/index',array('con'=>'clothes','act'=>'index')));
			}else{
				$this->error('审核失败');
			}
		}
		$data = DB::name('clothes_order')->where('id = '.$id)->find();
		$category = $this->getCategoryList();
		$color 	  = $this->getColorList();
		$size 	  = $this->getSizeList();
		return $this->fetch('cai',[
			'data'			=>		$data,
			'category'		=>		$category,
			'color'			=>		$color,
			'size'			=>		$size,	

		]);
	}

	/*成衣订单的驳回*/
	public function gobackForCai()
	{
		if(Request::instance()->isPost())
		{
			$data['reaon'] = Request::instance()->post('reaon');
			$id 		   = Request::instance()->post('orderid');
			$data['caiwu_id'] = Session::get('manage_id');
			$data['caiwu_time'] = time();
			$data['status'] = 'reject';
			$res = DB::name('clothes_order')->where('id = '.$id)->setField($data);
			if($res)
			{
				$this->success('订单驳回成功',url('index/index/index',array('con'=>'clothes','act'=>'index')));
			}else{
				$this->error('订单驳回失败');
			}
		}
	}
	/*成衣订单修改页面*/
	public function update($id)
	{
		/*判断权限*/
		$authmenu = new \think\Authmenu();
		$uid = Session::get('manage_id');
		$auth=$authmenu->check($uid,'clothes_update');
		if($auth !=true)
		{
			$this->error('权限不足');
		}	
		if(Request::instance()->isPost())
		{
			$data = Request::instance()->post();
			$data['status'] = 'caiwu';
			$id = $data['id'];
			unset($data['id']);
			$res = DB::name('clothes_order')->where('id ='.$id)->setField($data);
			if($res)
			{
				$this->success('修改成功',url('index/index/index',array('con'=>'clothes','act'=>'index')));
			}else{
				$this->error('修改失败');
			}
		}
		$data = DB::name('clothes_order')->where('id = '.$id)->find();
		$category = $this->getCategoryList();
		$color 	  = $this->getColorList();
		$size 	  = $this->getSizeList();
		return $this->fetch('add_order',[
			'data'			=>		$data,
			'category'		=>		$category,
			'color'			=>		$color,
			'size'			=>		$size,	

		]);
	}

	/*成衣订单上传功能*/
	public function upload()
	{
		/*判断权限*/
		$authmenu = new \think\Authmenu();
		$uid = Session::get('manage_id');
		$auth=$authmenu->check($uid,'clothes_upload');
		if($auth !=true)
		{
			$this->error('权限不足');
		}	
		if(request::instance()->isPost()){
			$order_id = request::instance()->post('order_id');
			$file = request()->file("img");
				    // 移动到框架应用根目录/public/uploads/ 目录下
			if($file){
				$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
				if($info){
				            // 输出 20160820/42a79759f284b767dfcb2a0197904287.jpg
					$url =  $info->getSaveName();
					$url = 'public' . DS . 'uploads/'.$url;
					$data['url'] = $url;
					$data['upload_id'] = Session::get('manage_id');
					$data['upload_time']  = $data['upload_time'] = time();
					$data['status'] = 'upload';
					$res = DB::name('clothes_order')->where('id = '.$order_id)->setField($data);
					if($res){
						$this->success('上传成功',url('index/index/index',array('con'=>'clothes','act'=>'index')));
					}
				}else{
				            // 上传失败获取错误信息
					echo $file->getError();
				}
			}
		}
	}

	/*成衣订单 下载压缩包的方法*/
	public function ajaxDownload()
	{

		if(request::instance()->isPost())
		{
			$authmenu = new \think\Authmenu();
			$uid = Session::get('manage_id');
			$auth=$authmenu->check($uid,'clothes_dow');
			if($auth != true){
				$re['msg'] = -1;
				return json($re);
			}
			$id = request::instance()->post('id');
			$order['download_id'] = Session::get('manage_id');
			$order['download_time'] = time();
			$order['status'] = 'download';
			$res = DB::name('clothes_order')->where('id ='.$id)->setField($order);
			if($res){
				$url = DB::name('clothes_order')->where('id = '.$id)->value('url');
				$re['url'] = 'http://'.$_SERVER['HTTP_HOST'].'/'.$url;
				$re['msg'] = 1;
			}else{
				$re['msg'] = 0;
			}
			return json($re);
		}
	}

	/*成衣填写运单号的方法*/
	public function yundan()
	{
		if(request::instance()->isPost())
		{
			$authmenu = new \think\Authmenu();
			$uid = Session::get('manage_id');
			$auth=$authmenu->check($uid,'clothes_fahuo');
			if($auth != true){
				$this->error('权限不足');
			}else{
				$data['yundan_num'] = request::instance()->post('yundan_num');
				$id = request::instance()->post('orderid');
				$data['status'] = 'success';
				$data['fahuo_time'] = time();
				$res = DB::name('clothes_order')->where('id = '.$id)->setField($data);
				if($res){
					$this->success('发货成功',url('index/index/index',array('con'=>'clothes','act'=>'index')));
				}else{
					$this->error('发货失败');
				}
			}
		}
	}
	/*成衣订单展示页面*/
	public function show($id)
	{
		$data = DB::name('clothes_order')->where('id = '.$id)->find();
		if(empty($data['caiwu_id']) && empty($data['caiwu_time']))/*获取财审信息*/
		{
			$data['caiwu_name'] = $data['caiwu_time'] = '暂无';
		}else{
			$data['caiwu_name'] = DB::name('user')->where('id = '.$data['caiwu_id'])->value('truename');
			$data['caiwu_time'] = date('Y-m-d H:i:s',$data['caiwu_time']);
		}
		if(empty($data['upload_id']) && empty($data['upload_time']))/*获取传版信息*/
		{
			$data['upload_name'] = $data['upload_time'] = '暂无';
		}else{
			$data['upload_name'] = DB::name('user')->where('id ='.$data['upload_id'])->value('truename');
			$data['upload_time'] = date('Y-m-d H:i:s',$data['upload_time']);
		}
		if(empty($data['download_id']) && empty($data['download_time']))/*获取下载压缩包信息*/
		{
			$data['download_name'] = $data['download_time'] = '暂无';
		}else{
			$data['download_name'] = DB::name('user')->where('id = '.$data['download_id'])->value('truename');
			$data['download_time'] = date('Y-m-d H:i:s',$data['download_time']);
		}
		if(empty($data['code_id']) && empty($data['code_time']))/*获取条形码生成的信息*/
		{
			$data['code_name'] = $data['code_time'] = '暂无';
		}else{
			$data['code_name'] = DB::name('user')->where('id= '.$data['code_id'])->value('truename');
			$data['code_time'] = date('Y-m-d H:i:s',$data['code_time']);
		}
		$category = $this->getCategoryList();
		$color 	  = $this->getColorList();
		$size 	  = $this->getSizeList();
		return $this->fetch('show',[
			'data'			=>		$data,
			'category'		=>		$category,
			'color'			=>		$color,
			'size'			=>		$size,			
		]);
	}

	/*========================================条码生成部分=============================================================*/
	/*批量导出数据*/
	public function excel($attr)
	{
		$authmenu = new \think\Authmenu();
			$uid = Session::get('manage_id');
			$auth=$authmenu->check($uid,'clothes_daochu');
			if($auth != true){
				$this->error('权限不足');
		}
		$where['id'] = $update['id']= array('in',$attr);
		$res = DB::name('clothes_code')->where($update)->setField('status',1);
		if($res)
		{
			$name='成衣条码列表';
			$header=['名称','条码编号','所属季节','所属品类','颜色','号型','价格','面料编号','面料属性','数量'];
			$where['is_del'] = 0;
			/*获取到id 然后查询这些id所对应的信息 最后放在表格里面*/
			$list = DB::name('clothes_code')->where($where)->order('id desc')->select();
			$str = array();
			foreach ($list as $k => $v) {
				$list[$k]['sex'] = $v['sex'] == 8 ? '男' : '女';
				switch ($v['season']) {
					case '1':
					$v['season'] = '春季';
					break;
					case '2':
					$v['season'] = '夏季';
					break;
					case '3':
					$v['season'] = '秋季';
					break;
					case '4':
					$v['season'] = '冬季';
					break;	
				}
				$v['category'] = DB::name('clothes_category')->where('id ='.$v['category'])->value('value');
				$v['color']	   = DB::name('clothes_color')->where('id = ' .$v['color'])->value('value');
				$v['size']     = DB::name('clothes_size')->where('id = '.$v['size'])->value('value');	
				$str[] = [$v['name'],$v['code'],$v['season'],$v['category'],$v['color'],$v['size'],$v['price'],$v['ml_num'],$v['ml_style'],$v['num']];
			}
			$data=$str;
			excelExport($name,$header,$data);
		}else{
			$this->error('已导出的数据请不要重复导出');
		}
	}

	/*导出数据一条*/
	public function exportOne($id)
	{
		$authmenu = new \think\Authmenu();
			$uid = Session::get('manage_id');
			$auth=$authmenu->check($uid,'clothes_daochu');
			if($auth != true){
				$this->error('权限不足');
		}
		$res = DB::name('clothes_code')->where('id = '.$id)->setField('status',1);
		if($res)
		{
			$name='成衣条码列表';
			$header=['名称','条码编号','所属季节','所属品类','颜色','号型','价格','面料编号','面料属性','数量'];
			/*获取到id 然后查询这些id所对应的信息 最后放在表格里面*/
			$list = DB::name('clothes_code')->where('id = '.$id)->find();
			$list['sex'] = $list['sex'] == 8 ? '男' : '女';
			switch ($list['season']) {
				case '1':
				$list['season'] = '春季';
				break;
				case '2':
				$list['season'] = '夏季';
				break;
				case '3':
				$list['season'] = '秋季';
				break;
				case '4':
				$list['season'] = '冬季';
				break;	
			}
			$list['category'] = DB::name('clothes_category')->where('id ='.$list['category'])->value('value');
			$list['color']	   = DB::name('clothes_color')->where('id = ' .$list['color'])->value('value');
			$list['size']     = DB::name('clothes_size')->where('id = '.$list['size'])->value('value');	
			$str[] = [$list['name'],$list['code'],$list['season'],$list['category'],$list['color'],$list['size'],$list['price'],$list['ml_num'],$list['ml_style'],$list['num']];

			$data=$str;
			excelExport($name,$header,$data);
		}
	}
	/*生成成衣条形码方法*/
	public function create($id)
	{
		/*先判断有没有权限*/
		$authmenu = new \think\Authmenu();
		$uid = Session::get('manage_id');
		$auth=$authmenu->check($uid,'clothes_code');
		if($auth !=true){/**/
				$this->error('权限不足');
		}

		if(Request::instance()->isPost())
		{
			$data = Request::instance()->post();
			$data['addtime'] = $data['updatetime'] =$num['addtime']  = $order['code_time'] = time();
			$data['entry_id'] = $num['entry_id'] = $order['code_id'] = Session::get('manage_id');
			$data['status']	= 0;
			$num['code'] = $order['code'] = $data['code'];
			$num['num']  = $data['num'];
			$order['status'] = 'code';
			$res = DB::name('clothes_code')->insert($data);//插入条码列表
			if($res){
				/*修改订单状态为待发货*/
				$resault = DB::name('clothes_order')->where('id = '.$id)->setField($order);	
					//$resault = DB::name('clothes_code_num')->insert($num);//插入条码录入批次表
				if($resault){
					$this->success('条码生成成功',url('index/index/index',array('con'=>'clothes','act'=>'codeList')));
				}
			}
			
		}
		$data = DB::name('clothes_order')->where('id = '.$id)->find();
		$category = $this->getCategoryList();//获取品类
		$color 	  = $this->getColorList();//获取颜色
		$size 	  = $this->getSizeList();//获取尺码
		return $this->fetch('create',[
			'category'		=>	$category,
			'color'			=>	$color,	
			'size'			=>	$size,
			'data'			=>	$data,	
		]);
	}


	/*临时添加条码*/
	/*生成成衣条形码方法*/
	public function tianjia()
	{
		/*先判断有没有权限*/
		$authmenu = new \think\Authmenu();
		$uid = Session::get('manage_id');
		$auth=$authmenu->check($uid,'clothes_code');
		if($auth !=true){/**/
				$this->error('权限不足');
		}

		if(Request::instance()->isPost())
		{
			$data = Request::instance()->post();
			$data['addtime'] = $data['updatetime'] =$num['addtime']  = $order['code_time'] = time();
			$data['entry_id'] = $num['entry_id'] = $order['code_id'] = Session::get('manage_id');
			$data['status']	= 0;
			$num['code'] = $order['code'] = $data['code'];
			$num['num']  = $data['num'];
			$order['status'] = 'code';
			$res = DB::name('clothes_code')->insert($data);//插入条码列表
			if($res){
					$this->success('条码生成成功',url('index/index/index',array('con'=>'clothes','act'=>'codeList')));
			}
			
		}
		$category = $this->getCategoryList();//获取品类
		$color 	  = $this->getColorList();//获取颜色
		$size 	  = $this->getSizeList();//获取尺码
		return $this->fetch('tianjia',[
			'category'		=>	$category,
			'color'			=>	$color,	
			'size'			=>	$size,
		]);
	}

	/*条码列表*/
	public function codeList()
	{
		if(Request::instance()->isPost())
		{
			$name = Request::instance()->post('name');
			$aa = preg_match('/[\x{4e00}-\x{9fa5}]/u', $name);/*判断里面有没有汉字*/
			if($aa == 1){/*说明有汉字，那就是暗名称搜*/
				$where['name'] = array('like',"%$name%");	
			}else{/*没有就是面料编号*/
				$where['code'] = array('like',"%$name%");
			}
		}
		$where['is_del'] = 0;
		$list = DB::name('clothes_code')->where($where)->order('id desc')->paginate(15);
		$page = $list->render();
		$list = $list->all();
		foreach ($list as $k => $v) {
			$list[$k]['sex'] = $v['sex'] == 8 ? '男' : '女';
			switch ($v['season']) {
				case '1':
				$list[$k]['season'] = '春季';
				break;
				case '2':
				$list[$k]['season'] = '夏季';
				break;
				case '3':
				$list[$k]['season'] = '秋季';
				break;
				case '4':
				$list[$k]['season'] = '冬季';
				break;	
				
			}
			$list[$k]['category'] = DB::name('clothes_category')->where('id ='.$v['category'])->value('value');
			$list[$k]['color']	  = DB::name('clothes_color')->where('id = ' .$v['color'])->value('value');
			$list[$k]['size']     = DB::name('clothes_size')->where('id = '.$v['size'])->value('value');	
		}

		return $this->fetch('code_list',[
			'list'  => $list,
			'page'	=> $page,
		]);
	}
	/*修改条形码状态*/
	public function updateStatus()
	{
		if(Request::instance()->isPost())
		{
			$id = Request::instance()->post('id');
			$data['status'] = 1;
			$data['updatetime'] = time();
			$res = DB::name('clothes_code')->where('id = '.$id)->setField($data);
			if($res){
				return 1;
			}else{
				return 2;
			}
		}
	}
	/*添加条码数量*/
	public function addnum()
	{
		if(Request::instance()->isPost())
		{
			$data = Request::instance()->post();
			$data['addtime'] = time();
			$data['entry_id'] = Session::get('manage_id');
			$res = DB::name('clothes_code_num')->insert($data);//在编码批次表中插入数据
			if($res)
			{
				$resault = DB::name('clothes_code')->where("code = '".$data['code']."'")->setInc('num',$data['num']);
				$r = DB::name('clothes_code')->where("code = '".$data['code']."'")->setField('updatetime',$data['addtime']);
				if($resault && $r){
					$this->success('添加数量成功',url('index/index/index',array('con'=>'clothes','act'=>'codeList')));
				}
			}

		}
	}
	/*删除订单 -----  只修改状态  不删除数据*/
	public function delorder()
	{
		if(Request::instance()->isPost())
		{
			$id = Request::instance()->post('id');
			/*判断权限*/
			$authmenu = new \think\Authmenu();
			$uid = Session::get('manage_id');
			$auth=$authmenu->check($uid,'clothes_del');
			if($auth !=true){//没有删除菜单的权限
				$res['sta'] = '-1';
				$res['msg'] = '权限不足';
				
			}else{
				$del = DB::name('clothes_order')->where('id = '.$id)->setField('is_del',1);
				if($del){
					$res['sta'] = '1';
					$res['msg'] = '删除成功';
				}else{
					$res['sta'] = '0';
					$res['msg'] = '删除失败';
				}
			}
			return json($res);
		}
	}

		/*删除条码 -----  只修改状态  不删除数据*/
	public function delcode()
	{
		if(Request::instance()->isPost())
		{
			$id = Request::instance()->post('id');
			/*判断权限*/
			$authmenu = new \think\Authmenu();
			$uid = Session::get('manage_id');
			$auth=$authmenu->check($uid,'clothes_delCode');
			if($auth !=true){//没有删除菜单的权限
				$res['sta'] = '-1';
				$res['msg'] = '权限不足';
				
			}else{
				$del = DB::name('clothes_code')->where('id = '.$id)->setField('is_del',1);
				if($del){
					$res['sta'] = '1';
					$res['msg'] = '删除成功';
				}else{
					$res['sta'] = '0';
					$res['msg'] = '删除失败';
				}
			}
			return json($res);
		}
	}
	/*获取成衣的品类列表*/
	public function getCategoryList()
	{
		return DB::name('clothes_category')->order('id asc')->select();
	}
	/*获取成衣的颜色列表*/
	public function getColorList()
	{
		return DB::name('clothes_color')->order('id asc')->select();
	}

	/*获取成衣尺码列表*/
	public function getSizeList()
	{
		return DB::name('clothes_size')->order('id asc')->select();
	}


	//导入
    public function inserExcel()
    {
		//import('phpexcel.PHPExcel', EXTEND_PATH);//方法二
        vendor("PHPExcel.PHPExcel"); //方法一
        $objPHPExcel = new \PHPExcel();
 		if(Request::instance()->isPost())
 		{
	        //获取表单上传文件
			$file = request()->file('excel');
	        $info = $file->validate(['size'=>15678,'ext'=>'xlsx,xls,csv'])->move(ROOT_PATH . 'public' . DS . 'excel');
			if($info){
	            $exclePath = $info->getSaveName();  //获取文件名
	            $file_name = ROOT_PATH . 'public' . DS . 'excel' . DS . $exclePath;   //上传文件的地址
	            $objReader =\PHPExcel_IOFactory::createReader('Excel5');
	            $obj_PHPExcel =$objReader->load($file_name, $encode = 'utf-8');  //加载文件内容,编码utf-8
	            echo "<pre>";
	            $excel_array=$obj_PHPExcel->getsheet(0)->toArray();   //转换为数组格式
	            array_shift($excel_array);  //删除第一个数组(标题);
	            $data = [];
				$i=0;
	            foreach($excel_array as $k=>$v) {
	                $data[$k]['title'] = $v[0];
					$i++;
	            }
	           $success=Db::name('t_station')->insertAll($data); //批量插入数据
			   $error=$i-$success;
	            echo "总{$i}条，成功{$success}条，失败{$error}条。";
	           // Db::name('t_station')->insertAll($city); //批量插入数据
			}else{
				// 上传失败获取错误信息
				echo $file->getError();
			}
		}else{
			return $this->fetch();
		}
    }


}